﻿@using Novagoal.Website.Models.Views
@using Novagoal.Website.WebApp.Helpers

@model HomeViewModel
@{
    ViewBag.Title = "Novagoal | Principal";
    Layout = "~/Views/Shared/MasterLayout.cshtml";
}

@section PageContent {
    <script src="@Url.Content("~/Scripts/novagoal-home.js")" type="text/javascript"></script>

    <div class="main-content ui-corner-top">
        <div class="ui-widget-header ui-corner-all">
            <div class="title">Principal</div>
        </div>

        <div style="width:100%; display:inline-block">
            <div class="ui-widget-content ui-corner-bottom" style="float:left">
                <embed type="application/x-shockwave-flash" src="http://www.fifa.com/flash/widgets/photogallery/app.swf?lang=en" width="300" height="400" style="undefined" id="flashLatestPhoto" name="flashLatestPhoto" bgcolor="#ffffff" quality="high" wmode="transparent" flashvars="lang=en">
            </div>   
            <div style="overflow:auto; height:445px">
                <div id="tabs" style="border-bottom-style:none">
	                <ul>
                        <li><a href="#tabs-messages">Mensajes</a></li>
                        @foreach(var ranking in Model.Rankings)
                        {
                            <li><a href="#@ranking.Party.Id">@ranking.Party.Name</a></li>
                        }
                        @foreach (var globalRanking in Model.GlobalRankings)
                        {
                            <li><a href="#@globalRanking.Key.Id">@globalRanking.Key.Name (Tabla General)</a></li>    
                        }
	                </ul>
                    @foreach(var ranking in Model.Rankings)
                    {
	                    <div id="@ranking.Party.Id">
                            <div style="text-align:center">
                                <a href="@Url.Action("View", "Parties", new { id=ranking.Party.Id })">@Html.CreateImage(ranking.Party.Tournament.TrophyPath, new { height="60px" })</a>
                            </div>
                            Presiona el logo del torneo para ir a la pagina principal del grupo.
                            <table class="main-table">
                                <tr>
                                    <th class="ui-widget-header ui-corner-all">Posicion</th>
                                    <th class="ui-widget-header ui-corner-all">Nombre</th>
                                    <th class="ui-widget-header ui-corner-all">Equipo</th>
                                    <th class="ui-widget-header ui-corner-all">Puntos</th>
                                </tr>
                            @{var pos = 1;}
                            @foreach(var entry in ranking.RankingEntries){
                                <tr>
                                    <td class="center">@pos</td>
                                    <td><span>@Html.GetAvatar(entry.Person.Id, new { style = "height:50px; width:50px; vertical-align:middle" }) @entry.Person.FullName</span></td>
                                    <td>@Html.TeamSpan(entry.Team)</td>
                                    <td class="center">@entry.TotalPoints</td>
                                </tr>
                                pos++;
                            }
                            </table>
	                    </div>
                    }
                    @foreach (var globalRanking in Model.GlobalRankings)
                    {
                         <div id="@globalRanking.Key.Id">
                            <div style="text-align:center">
                                @Html.CreateImage(globalRanking.Key.TrophyPath, new { height = "60px" })
                            </div>
                            <table class="main-table">
                                <tr>
                                    <th class="ui-widget-header ui-corner-all">Posicion</th>
                                    <th class="ui-widget-header ui-corner-all">Nombre</th>
                                    <th class="ui-widget-header ui-corner-all">Equipo</th>
                                    <th class="ui-widget-header ui-corner-all">Puntos</th>
                                </tr>
                            @{var pos = 1;}
                            @foreach (var entry in globalRanking.Value)
                            {
                                <tr>
                                    <td class="center">@pos</td>
                                    <td><span>@Html.GetAvatar(entry.Person.Id, new { style = "height:50px; width:50px; vertical-align:middle" }) @entry.Person.FullName</span></td>
                                    <td>@Html.TeamSpan(entry.Team)</td>
                                    <td class="center">@entry.TotalPoints</td>
                                </tr>
                                pos++;
                            }
                            </table>
	                    </div>
                    }
	                <div id="tabs-messages">
                        <h2>Bienvenido a NovaGoal</h2>
                        <p>
                            La seleccion del mejor jugador del partido viene de la pagina oficial de la UEFA.
                        </p>
                        <iframe src='http://www.uefa.com/uefaeuro/season=2012/man-of-the-match-award/library/widget/_widgetSA.html' scrolling='no' frameborder='0' style="height:260px; width:310px"></iframe>
	                </div>
                </div>             
            </div>
        </div>

        @{Html.RenderPartial("SubmitResults"); }
        <div class="ui-widget-content ui-corner-bottom" style="overflow:auto">
            
            <div style="float:left; width:48%; overflow:auto">
                <div class="ui-widget-header ui-corner-all">
                    <div class="title">Proximos Partidos</div>
                </div>
                <div id='upcomingGamesResult' style='padding:2px; display:none'></div>
                <div class="ui-widget-content ui-corner-bottom">
                    @using (@Html.BeginForm("UpdateResults", "Games", FormMethod.Post, new { id = "upcomingGamesForm" }))
                    {
                        foreach (var game in Model.UpcomingGames)
                        {
                            <div class="upcomingGame" >
                                <div style="padding:2px" class='ui-widget-header ui-corner-all changeToLocalDateTime'>@game.StartedAt.ToString("MM/dd/yyyy HH:mm")</div>
                                <div style="margin:6px; margin-top:12px">
                                    @{
                                        var mvpName = game.PredictedResult.Player != null ? game.PredictedResult.Player.Name : "Presiona aqui";
                                        var mvpId = game.PredictedResult.Player != null ? game.PredictedResult.Player.Id : 0;
                                    }
                                    <span>Jugador mas valioso: </span>
                                    <a id="MvpName-@game.Id" href="javascript:OpenMVPSelection(@game.Id)">@mvpName</a>
                                    <input id="MvpId-@game.Id" name="Mvp" type="hidden" value="@mvpId" />
                                </div>
                                <a href="javascript:ShowGameHistoy(@game.TeamA.Id)">@Html.TeamSpan(game.TeamA)</a>
                                @Html.TextBox("TeamA", game.PredictedResult.TeamAScore, new { style = "width:20px" }) 
                                <span> vs </span>
                                @Html.TextBox("TeamB", game.PredictedResult.TeamBScore, new { style = "width:20px" })  
                                <a href="javascript:ShowGameHistoy(@game.TeamB.Id)">@Html.TeamSpan(game.TeamB)</a>
                                @Html.Hidden("GameId", game.Id)
                            </div>   
                        }
                        if (Model.UpcomingGames == null || Model.UpcomingGames.Count == 0)
                        {
                            <p>No hay mas partidos</p>
                        }
                        else{
                            <div style="text-align:center">
                            <input type="button" class="button ui-state-default ui-corner-all" onclick="UpdateResults()" value="Guardar" />
                            </div>
                        }
                    }
                </div>

                @if(Model.GamesInProgress.Count > 0){
                    <div class="ui-widget-header ui-corner-all">
                        <div class="title">Juegos en Progreso</div>
                    </div>
                    <div class="ui-widget-content ui-corner-bottom">
                        @foreach (var game in Model.GamesInProgress)
                        {
                            <div class="upcomingGame" >
                            <div style="padding:2px" class='ui-widget-header ui-corner-all changeToLocalDateTime'>@game.StartedAt.ToString("MM/dd/yyyy HH:mm")</div>
                                <div>
                                    <div style="margin:8px">
                                        <span>Jugador mas valioso: </span>
                                        @{var realMvp = game.PredictedResult.Player != null ? game.PredictedResult.Player.Name : "-";}
                                        <span style="font-weight:bold">@realMvp</span>
                                    </div>
                                    @Html.TeamSpan(game.TeamA)
                                    @{var teamAScore = game.PredictedResult.Id == 0 ? "-" : game.PredictedResult.TeamAScore.ToString();}
                                    <span style="font-size:15px; font-weight:bold"> @teamAScore </span>
                                    <span> vs </span>
                                    @{var teamBScore = game.PredictedResult.Id == 0 ? "-" : game.PredictedResult.TeamBScore.ToString();}
                                    <span style="font-size:15px; font-weight:bold"> @teamBScore </span>
                                    @Html.TeamSpan(game.TeamB)
                                    <br /><a href="javascript:ResultsPreview(@game.Id, '@game.TeamA.Name', '@game.TeamB.Name')">Ver todos los resultados</a>
                                </div>
                            </div>   
                        }
                    </div>
                }
            </div>

            <div style="float:right; width:48%; overflow:auto">
                <div class="ui-widget-header ui-corner-all">
                    <div class="title">Partidos Finalizados</div>
                </div>
                <div class="ui-widget-content ui-corner-bottom">
                    @if (Model.UpcomingGames == null || Model.UpcomingGames.Count == 0)
                    {
                        <p>Ya no hay mas partidos</p>
                    }
                    @foreach (var game in Model.FinishedGames)
                    {
                        <div class="upcomingGame" >
                        <div style="padding:2px" class='ui-widget-header ui-corner-all changeToLocalDateTime'>@game.StartedAt.ToString("MM/dd/yyyy HH:mm")</div>
                            <div style="float:right; color:#FF4500; padding-top:10px">
                                <span style="font-size:15px">Puntos</span><br />
                                @{var pointEarned = game.PredictedResult != null ? game.PredictedResult.Points : 0;}
                                <span style="font-size:30px; font-weight:bold">@pointEarned</span>
                            </div>
                            <div>
                                <div style="margin:8px">
                                    <span>Jugador mas valioso: </span>
                                    @{var realMvp = game.ActualResult.Player != null ? game.ActualResult.Player.Name : "-";}
                                    <span style="font-weight:bold">@realMvp</span>
                                </div>
                                @Html.TeamSpan(game.TeamA, 20)
                                <span style="font-size:15px; font-weight:bold"> @game.ActualResult.TeamAScore </span>
                                <span> vs </span>
                                <span style="font-size:15px; font-weight:bold"> @game.ActualResult.TeamBScore </span>
                                @Html.TeamSpan(game.TeamB, 20)
                                <div style="margin-top:10px">
                                    <span>Tu marcador: </span>
                                    @{var predictedScore = game.PredictedResult != null ? string.Format("{0} - {1}", game.PredictedResult.TeamAScore, game.PredictedResult.TeamBScore) : "None";}
                                    <span>@predictedScore</span>
                                    <br />
                                    @{var mvpPredicted = game.PredictedResult != null && game.PredictedResult.Player != null ? game.PredictedResult.Player.Name : "None";}
                                    <span>El jugador que seleccionaste: @mvpPredicted</span>
                                </div>
                            </div>
                        </div>   
                    }
                </div>
            </div>

        </div>
    </div>
}


